package condominio.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import condominio.excepcion.DAOExcepcion;
import condominio.modelo.Queja;
import condominio.util.ConexionBD;


//Insertar 
public class QuejaDAO extends BaseDAO {

	public Queja insertar(Queja vo) throws DAOExcepcion {
		System.out.println("QuejaDAO: insertar()");
		String query = "INSERT INTO queja(tipoQueja, detalleQueja) VALUES (?,?)";
		Connection con = null;
		PreparedStatement stmt = null;
		try {
			con = ConexionBD.obtenerConexion();
			stmt = con.prepareStatement(query);
			//stmt.setInt(1, vo.getIdResidente());
			stmt.setString(1, vo.gettipoQueja());
			stmt.setString(2, vo.getdetalleQueja());
			
			
			int i = stmt.executeUpdate();
			if (i != 1) {
				throw new SQLException("No se pudo insertar");
			}
		} catch (SQLException e) {
			System.err.println(e.getMessage());
			throw new DAOExcepcion(e.getMessage());
		} finally {
			this.cerrarStatement(stmt);
			this.cerrarConexion(con);
		}
		return vo;
	}
	
}
